package java1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.Map;
import java.util.Map.Entry;

public class Fivethree {
	public static void main(String[] args) {
		
	
		Scanner input=new Scanner(System.in);
		Map<String,Integer>map=new HashMap<String ,Integer>();
		String x;
		while(true){
			x=input.next();
			if(x.equals("!!!!!"))break;
			
			if(map.containsKey(x)) map.put(x, map.get(x)+1);
			if(map.get(x)==null)	 map.put(x, 1); 
			}
     System.out.println(map.size());
		List<Entry<String,Integer>> list =new ArrayList<Entry<String,Integer>>(map.entrySet());
         Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
			public int compare(Map.Entry<String, Integer> o1,Map.Entry<String, Integer> o2) {
	   			  if (o1.getValue() != o2.getValue()) {
			         return o2.getValue() - o1.getValue();
					} 
				  else {
						return o1.getKey().compareTo(o2.getKey());
					}
				}
		});

	for(int i=0;i<10;i++){
			System.out.println(list.get(i));
		}

	}

}

